home *** CD-ROM | disk | FTP | other *** search
- /*
- File: BTreeTupleDatabase.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __BTREETUPLEDATABASE__
- #define __BTREETUPLEDATABASE__
-
- #ifndef __TUPLEDATABASE__
- #include "TupleDatabase.h"
- #endif
-
- #ifndef __BTEQU__
- #include "BTEqu.h"
- #endif
-
- #ifndef __FILESPEC__
- #include "FileSpec.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- /***********************************|****************************************/
-
-
- typedef short (*BTreeCompareProc) ( /* const void* searchInA0, const void* trial */ );
-
- class AKeyDescriptor : public TDirectObject
- {
- public:
-
- static const AKeyDescriptor& kString;
- static const AKeyDescriptor& kCompareProc;
-
- virtual ~AKeyDescriptor ();
-
- virtual const unsigned char* GetBtreeDescriptor () const = 0;// subclasses must override
- virtual unsigned long GetMaxKeyLength () const; // returns MaxKeyLen
- virtual const BTreeCompareProc GetCompareProc () const; // returns nil
-
- virtual ostream& operator >> ( ostream& ) const;
- virtual void PrintDescriptor ( ostream&, const unsigned char* ) const;
-
- protected: AKeyDescriptor ();
- };
-
- /***********************************|****************************************/
-
- class TBTreeKeyWrapper;
-
- class TBTreeDatabase : public ATupleDatabase
- {
- public:
-
- enum Mode { kReadOnly, kReadWriteNew, kReadWriteOld };
- enum Rights { kNonExclusive, kExclusive };
-
- TBTreeDatabase ( const TFileSpec&, const AKeyDescriptor&, Mode = kReadWriteOld, Rights = kNonExclusive );
- virtual ~TBTreeDatabase ();
-
- virtual Boolean SetTuple ( const ATupleKey&, const ADataItem& );
- virtual Boolean SetTuple ( unsigned long index, const ADataItem& );
-
- virtual Boolean GetTuple ( unsigned long index, ATupleKey&, ADataItem& );
- virtual Boolean GetTupleData ( const ATupleKey&, ADataItem& );
- virtual Boolean GetTupleData ( unsigned long index, ADataItem& );
- virtual Boolean GetTupleKey ( unsigned long index, ATupleKey& );
- virtual Boolean GetTupleDataSize ( const ATupleKey&, unsigned long& );
-
- virtual Boolean DeleteTuple ( const ATupleKey& );
-
- virtual CTupleKey* CreateKey ( unsigned long index );
- virtual Boolean FindIndexOfTuple ( const ATupleKey&, unsigned long& index ) const;
- virtual Boolean DoesTupleExist ( const ATupleKey& ) const;
- virtual unsigned long CountTuples () const;
-
- virtual void Flush ();
- virtual Boolean DeleteDatabase ();
-
- virtual Boolean ReserveAccess ();
- virtual Boolean ReleaseAccess ();
-
- // error handling and debugging
-
- virtual ostream& operator >> ( ostream& ) const;
- OSErr GetError () const;
- virtual Boolean HandleError ( OSErr ) const;
- static const char* GetErrorName ( OSErr );
-
- protected: unsigned long GetTupleDataSize ( const TBTreeKeyWrapper& );
- virtual Boolean GetInfo ( BTParam& ) const;
- virtual void InvalidateHint ();
- static short ComparisonProc ();
-
- private: TBTreeDatabase ( const TBTreeDatabase& );
- TBTreeDatabase& operator = ( const TBTreeDatabase& );
-
- TFileSpec fFile;
- OSErr fError;
- Rights fRights;
- BTIOParam fParam;
- };
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #pragma push
- #pragma segment BtreeDatabase
-
- inline
- AKeyDescriptor::AKeyDescriptor ()
- {
- }
-
- /***********************************|****************************************/
-
- inline
- AKeyDescriptor::~AKeyDescriptor ()
- {
- }
-
- /***********************************|****************************************/
-
- inline unsigned long
- AKeyDescriptor::GetMaxKeyLength () const
- {
- return MaxKeyLen - 10;
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #pragma pop
-
- #endif // __BTREETUPLEDATABASE__
-
-